# -*- coding: UTF-8 -*-

# Copyright (C) 2009 Daniele Favara.
# Written by Daniele Favara <daniele@zeroisp.com>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

"""Main Controller"""

from pylons.i18n import ugettext as _, lazy_ugettext as l_
from repoze.what import predicates
from tg import config, url
from tgext.zeroisp.lib.base import BaseController
from tgext.zeroisp.lib.picasa_google_com import PicasaGoogleCom
from tw.api import *
from tw.forms import *
from tw.jquery.base import jquery_js

__all__ = ['PostController']


class DefaultController(BaseController):
    """
    """
    def __init__(self, root_url='/', controllers_map={}, *args, **kw):
        BaseController.__init__(self)
        self.root_url = root_url
        for k, v in controllers_map.iteritems():
            setattr(self, k, v(self.root_url))
        allow_only = predicates.not_anonymous(
                msg=l_('Only for people with the "manage" permission'))

    def _get_picasa(self):
        try:
            return PicasaGoogleCom(email=config.get('google.picasa.email'),
                         password=config.get('google.picasa.password'),
                         account_type=config.get('google.picasa.account_type'),
                         user=config.get('google.picasa.user'),
                         thumbsizes=[config.get('google.picasa.thumbsizes')],
                         imgmax = config.get('google.picasa.imgmax')
                               )
        except:
            #raise
            return None

    picasa = property(_get_picasa)


    def googlemaps_js(self, simple=True):
        googlemaps_js = JSLink(
            link='http://www.google.com/jsapi?key=%s'%(
                                            config.get('google.maps.key')))
        class GoogleMap(Widget):
            javascript = [googlemaps_js]
        return GoogleMap()


